Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ESLint plugins with "type": "module" and main in package.json #598

Merged
merged 2 commits into from
Dec 31, 2024

Conversation

y-hsgw
Copy link
Contributor

@y-hsgw y-hsgw commented Dec 23, 2024

{
  "main": "./dist/index.js",
  "type": "module",
  ...
}

Fixed an issue where the following error occurred with a package.json using "type": "module":

require() of ES Module  ***/dist/index.js not supported.
Instead change the require of ***/dist/index.js to a dynamic import() which is available in all CommonJS modules.

#504 might be somewhat related to this.

@bmish bmish added the enhancement New feature or request label Dec 23, 2024
@bmish
Copy link
Owner

bmish commented Dec 23, 2024

Thanks for working on this. This is an important fix/support to add.

Is it possible to test this? Perhaps a new test fixture test/fixtures/esm and a test file lib/generate/esm-test.ts.

Also, do you know of a real-world eslint plugin example using ESM? I'll want to test this manually on one.

@bmish
Copy link
Owner

bmish commented Dec 23, 2024

The test looks good.

@bmish
Copy link
Owner

bmish commented Dec 23, 2024

  1. I'd like to manually test this on a real-world plugin if you know of any. If you aren't sure, I will look for one later.
  2. I believe this partially resolves Support ESM #504, handling module + main but not module + exports. We can try to handle module + exports later.

@y-hsgw
Copy link
Contributor Author

y-hsgw commented Dec 23, 2024

Also, do you know of a real-world eslint plugin example using ESM? I'll want to test this manually on one.

Sorry, nothing comes to mind right away.
However, in this case, I tested it within a repository I created for experimental purposes, and it seems to generate without any issues.

@ljharb
Copy link

ljharb commented Dec 23, 2024

(to be clear, type module has nothing to do with ESM support; it just changes how .js is parsed)

@bmish bmish changed the title feat: add support for projects with "type": "module" in package.json Support ESLint plugins with "type": "module" and main in package.json Dec 31, 2024
Copy link
Owner

@bmish bmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would find a real-world example to test this on, but I'm going to merge it anyway.

@bmish bmish merged commit a88f8cb into bmish:main Dec 31, 2024
8 checks passed
@y-hsgw y-hsgw deleted the feat/support-type-module branch December 31, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants